@extends('admin::layouts.master')

@section('content')
    <div class="col-lg-12">
        <div class="card card-table">
            <div class="card-header">
                分类管理
                <div class="mt-2">
                    <button type="button" class="btn btn-primary mr-2">分类列表</button>
                    <button data-toggle="modal" data-target="#addCategory" type="button"
                            class="btn btn-space btn-primary mt-1">
                        添加分类
                    </button>
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                    {{--@component第二个参数数组中的键名,会自动的变成变量名,传递到被调用的组件模板中去--}}
                    @component('components.modal',['title' => '添加分类','url' => '/shop/category','id' => 'addCategory'])
                        <div class="form-group">
                            <label>分类名称</label>
                            <input type="text" placeholder="请输入添加的分类的中文名称..." name="cname" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>父级分类</label>
                            <div class="col-12 col-sm-8 col-lg-12">
                                <select class="form-control" name="pid">
                                    <option value="0" selected="">顶级分类</option>
                                    @foreach($categorys as $v)
                                        <option value="{{$v['id']}}">{{$v['cname']}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                    @endcomponent
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                </div>
            </div>
            <div class="card-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>分类名称</th>
                        <th>父级分类</th>
                        <th class="actions">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($categorys as $v)
                        <tr>
                            <td>{{$v['id']}}</td>
                            <td>{!! $v['_cname'] !!}</td>
                            <td>{{$v['pid']}}</td>
                            <td class="actions">
                                <div class="btn-group btn-space">
                                    <a href="{{route ('category.edit',$v['id'])}}"class="btn btn-space btn-primary">
                                        编辑
                                    </a>
                                    <form action="{{route ('category.destroy',$v['id'])}}" method="post">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger mr-1">删除</button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@stop
